<?php 
    session_start();
    if($_SESSION['uid']==""||$_SESSION['level']!=2){
		exit();
	}
    include('/tool/submitValidate.php');
    include('/tool/pdo.php');
    include('/bll/PublicDataBLL.php');
    include('/class/public-data.class.php');
    include('/class/student-information-register.class.php');
    include('/class/class-dormitory-management.class.php');
    include('/class/student-dormitory-allocating.class.php');
    include('/bll/StudentDormitoryAllocatingBLL.php');

    $action = isset($_POST['action']) ? $_POST['action'] : 0;
    $data = isset($_POST['data']) ? $_POST['data'] : null;

    switch((int)$action){
        //分配宿舍
        case 1:
            $allocateList=json_decode($data);
            if(!$allocateList==null){
                $StudentDormitoryAllocatingBLL=new StudentDormitoryAllocatingBLL();
                $result=$StudentDormitoryAllocatingBLL->allocateStudentDorm($_SESSION['uid'],$allocateList);
            }
            break;
        case 2:
            break;
        //移除宿舍    
        case 3:
            $removeList=json_decode($data);
            if(!$removeList==null){
                $StudentDormitoryAllocatingBLL=new StudentDormitoryAllocatingBLL();
                $result=$StudentDormitoryAllocatingBLL->removeStudentDormitory($_SESSION['uid'],$removeList);
            }
            break;
        default:break;
    }

    echo json_encode($result,JSON_UNESCAPED_UNICODE);
?>